﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace ly.Web.QianTai
{
    public partial class Index : System.Web.UI.Page
    {
        ly.BLL.UserInfo userBll = new BLL.UserInfo();
        ly.BLL.WorkInfo workBll = new BLL.WorkInfo();
        ly.Model.WorkInfo workModel = new Model.WorkInfo();
        ly.BLL.news newsBLL = new BLL.news();
        ly.Model.news newsModel = new Model.news();
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Session["username"] == null)
            //{
            //    Response.Redirect("../Admin/Index.aspx");
            //}
            //else
            //{
                initLogin();
                BindData();
            //}
        }

        //查看用户是否登录
        public void initLogin()//初始化用户登录
        {
            if (Session["username"] != null)//判断用户是否登录
            {
                ly.Model.UserInfo model = new Model.UserInfo();
                model = userBll.GetModel(Session["username"].ToString());
                lblUserName.Text = model.UserName;
                pnlLogin.Visible = false;
                pnlLoginOut.Visible = true;
            }
            else
            {
                pnlLogin.Visible = true;
                pnlLoginOut.Visible = false;
            }
        }
        private void BindData()
        {

            string strwhere = "WorkVerify = '审核通过'order by UploadTime DESC";
            DataTable dt = workBll.GetList4(strwhere).Tables[0];
            PagedDataSource ps = new PagedDataSource();
            ps.DataSource = dt.DefaultView;
            ps.AllowPaging = true;
            //最新作品
            dlist.DataSource = ps;
            dlist.DataBind();
            //推荐作品
            string strtuijian = "WorkVerify = '审核通过'and Recommend = '是'";
            DataTable dttuijian = workBll.GetList4(strtuijian).Tables[0];
            PagedDataSource pstuijian = new PagedDataSource();
            pstuijian.DataSource = dttuijian.DefaultView;
            pstuijian.AllowPaging = true;
            DataList1.DataSource = pstuijian;
            DataList1.DataBind();
            //新闻列表
            //Common.BindRepeater(rptXinWen, 10);
            string strXinWenWhere = "";
            DataTable dtXinWen = newsBLL.GetList(strXinWenWhere).Tables[0];
            PagedDataSource psXinWen = new PagedDataSource();
            psXinWen.DataSource = dtXinWen.DefaultView;
            psXinWen.AllowPaging = true;
            rptXinWen.DataSource = psXinWen;
            rptXinWen.DataBind();
        }
    }
}